package no.sachmuld.methodcombination.examples.adapter.multipleinheritance;

import no.sachmuld.methodcombination.api.BehaviourChain;
import no.sachmuld.methodcombination.api.MethodInvocation;
import no.sachmuld.methodcombination.api.adapter.Default;

/**
 *
 */
public class Person {

    private BehaviourChain<PersonBehaviour> chain = new BehaviourChain<>();

    public Person(final String name) {

        with(new PersonBehaviour() {

            @Override
            public String toString(MethodInvocation<String> methodInvocation) {
                return name;
            }

        });

    }

    public final String toString() {
        return new Default<PersonBehaviour, String>(chain) {
            @Override
            protected String executeBehaviour(PersonBehaviour behaviour, MethodInvocation<String> methodInvocation) {
                return behaviour.toString(methodInvocation);
            }
        }.execute();
    }

    final protected Person with(PersonBehaviour... behaviours) {
        chain.addAll(behaviours);
        return this;
    }

}
